<?php
/**
 * Introduction: 代金券表  micro_shop_coupons
 */

namespace Common\Model;


use Think\Model;

class MicroShopCouponsModel extends Model
{
    //定义数据库连接信息
    protected $connection;

    //定义表名
    protected $tableName = 'micro_shop_coupons';

    /**
     * 初始化
     */
    public function _initialize()
    {

        $this->connection = C('Databaese');

    }

    /**
     * 获取代金券
     */
    public function getList($member_id){
       return $this->where("member_id=$member_id")->select();
    }

    /**
     * 获取单条数据
     */
    public function getOne($id){
        return $this->where("id=$id")->find();
    }

    /**
     * 添加优惠券
     *
     * @param $memberId
     * @param $packageId
     * @param $couponsKey
     * @param $couponsInfo
     * @return mixed
     */
    public function addCoupons($memberId,$packageId,$couponsKey,$couponsInfo){
        //$params = $couponsInfo;
        $couponsInfo['member_id'] = $memberId;
        $couponsInfo['package_id'] = $packageId;
        $couponsInfo['cpns_key'] = $couponsKey;
        $id = $this->add($couponsInfo);
        return $id;
    }

}